<?php
/**
 * Created by PhpStorm.
 * 
 */

class ModRoutineCrossSer extends Model {

    protected $table = 'routine_cross_server_server';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbOss;
    }

    public function addmuch($params){
    	$result = $this->getDbConnection()->multiInsert($params, $this->table, FALSE);
    	return $result;
    }
    
    /**
     * 根据常规跨服id获取所关联的服务器
     * @param unknown $id
     * @return unknown
     */
    public function getServer($id){
    	$sql = "SELECT s.id,s.server_name,s.server_num,s.name,r.routine_id FROM server as s INNER JOIN routine_cross_server_server as r ON r.server_id = s.id WHERE r.routine_id ={$id}";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    /**
     * 根据常规跨服id获取所配置的服务器
     * @param unknown $routine_id
     * @return unknown
     */
    public function getUseServer($routine_id){
    	$sql = "SELECT * FROM {$this->table} WHERE routine_id !={$routine_id}";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    public function deleteForIds($ids){
    	$sql = "delete from {$this->table} WHERE id in ({$ids})";
        $result = $this->getDbConnection()->execute($sql, $args);
        return $result;
    }
    
    public function deleteForServerIds($ids){
    	$sql = "delete from {$this->table} WHERE server_id in ({$ids})";
    	$result = $this->getDbConnection()->execute($sql, $args);
    	return $result;
    }
    
    public function deleteForRoutineIds($ids){
    	$sql = "delete from {$this->table} WHERE routine_id in ({$ids})";
    	$result = $this->getDbConnection()->execute($sql, $args);
    	return $result;
    }
    
    public function getRoutineServer($game){
    	$sql = "SELECT routine_id,server_id from routine_cross_server_server as ss INNER JOIN routine_cross_server as rc ON rc.id = ss.routine_id WHERE game ='{$game}' ";
    	$result = $this->getDbConnection()->getAll($sql, $args);
    	return $result;
    }
    
    
    
    
    
} 